package Datas_Structure.Sort;

import java.util.Arrays;

/**
 * 选择排序
 */
public class SelectSort_02 {
    public static void main(String[] args) {
        int[] arr = new int[]{4, 0 , 5 , 6, 7, 1, 3, 2};
        selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void selectSort(int[] arr) {
        //控制遍历的次数，即length-1次
        for (int i = 0; i < arr.length-1; i++) {
            //内层是需要循环的次数
         for (int j = i+1;j < arr.length ;j++){
            if (arr[i]>arr[j]){
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
          }
        }
    }

}

